/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bookstore.action;
import com.opensymphony.xwork2.*;
import bookstore.iservice.*;
import bookstore.service.*;
import bookstore.dao.*;
import bookstore.model.*;
/**
 *
 * @author cjx
 */
public class CustomerAction_1 extends ActionSupport
{
   private ICustomerService bsCustomerService =new CustomerService();
   private Customer bsCustomer=new Customer();
   private String msg;
   public void validate()
   {
       if((bsCustomer.getName()==null)||bsCustomer.getName().equals(""))
       {
           this.addFieldError("bsCustomer.name", "<br/>账户不能为空！ ");
       }
       if((bsCustomer.getPassword()==null)||bsCustomer.getPassword().equals(""))
       {
           this.addFieldError("bsCustomer.password", "<br/>密码不能为空！ ");
       }
       
   }
   public String execute()
   {   
       bsCustomerService.setCustomerDao(new CustomerDao());
       bsCustomer=bsCustomerService.findCustomerByNameAndPassword(
                              bsCustomer.getName(),
                              bsCustomer.getPassword());
       if(bsCustomer==null)
       {
           ActionContext.getContext().getSession().put("msg","the Current User is Guest");
           msg=ERROR;
       }       
       else
         {
             msg=SUCCESS;
             ActionContext.getContext().getSession().put("bsCustomer",bsCustomer);
          }
       return msg;
   }
   public Customer getBsCustomer(){return bsCustomer;}
   public void setBsCustomer(Customer bsCustomer){this.bsCustomer=bsCustomer;}
    
}
